package com.example.administrator_kunker.mjj_pro;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import butterknife.BindView;
import butterknife.ButterKnife;

public class SetActivity extends AppCompatActivity  implements View.OnClickListener{

    @BindView(R.id.set_ip)
    EditText set_ip;
    @BindView(R.id.set_port)
    EditText set_port;
    @BindView(R.id.set_but)
    EditText set_but;

    private SharedPreferences sp;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set);
        ButterKnife.bind(this);
        sp = getSharedPreferences("config", Context.MODE_PRIVATE);
        if(!sp.contains("ip")){
            sp.edit().putString("ip","127.0.0.1").commit();
        }
        if(!sp.contains("port")){
            sp.edit().putString("port","9111").commit();
        }
    }

    @Override
    public void onClick(View view) {
        if(view.getId() == R.id.set_but){
            sp.edit().putString("ip",set_ip.getText().toString())
                    .putString("port",set_port.getText().toString()).commit();
        }
    }
}
